package io.modifier.basic.emo.scheme

interface SchemeArgParser<T : Any> {
    fun parse(name: String, value: String): T
}

object SchemeBoolArgParser : SchemeArgParser<Boolean> {
    override fun parse(name: String, value: String): Boolean {
        if (value.isEmpty()) {
            return true
        }
        if (value == "1" || value == "true") {
            return true
        }
        if (value == "0" || value == "false") {
            return false
        }

        throw SchemeParseException("value($value) for $name can not convert to Boolean")
    }
}

object SchemeIntArgParser : SchemeArgParser<Int> {
    override fun parse(name: String, value: String): Int {
        return value.toInt()
    }
}

object SchemeLongArgParser : SchemeArgParser<Long> {
    override fun parse(name: String, value: String): Long {
        return value.toLong()
    }
}

object SchemeFloatArgParser : SchemeArgParser<Float> {
    override fun parse(name: String, value: String): Float {
        return value.toFloat()
    }
}

object SchemeStringArgParser : SchemeArgParser<String> {
    override fun parse(name: String, value: String): String {
        return value
    }
}
